[% setvar title Built-ins: Merge and generalize C<index> and C<rindex> %]
<div id="archive-notice">
    <h3>This file is part of the Perl 6 Archive</h3>
    <p>To see what is currently happening visit <a href="http://www.perl6.org/">http://www.perl6.org/</a></p>
</div>
<div class='pod'>
<a name='TITLE'></a><h1>TITLE</h1>
<p>Built-ins: Merge and generalize <code>index</code> and <code>rindex</code></p>
<a name='VERSION'></a><h1>VERSION</h1>
<pre>  Maintainer: Damian Conway &lt;<a href='mailto:damian@conway.org'>damian@conway.org</a>&gt;
  Date: 7 Aug 2000
  Mailing List: <a href='mailto:perl6-language@perl.org'>perl6-language@perl.org</a>
  Number: 53
  Version: 10
  Status: Developing</pre>
<a name='ABSTRACT'></a><h1>ABSTRACT</h1>
<p>This RFC proposes that the <code>index</code> and <code>rindex</code> functions be merged
and generalized, by adding a fourth parameter to <code>index</code>.</p>
<a name='DESCRIPTION'></a><h1>DESCRIPTION</h1>
<p>At present <code>index</code> only returns the index of the first occurrence of a
specified substring. It is proposed that <code>index</code> take a fourth parameter
telling it which occurrence of a specified substring to locate:</p>
<pre>        $first = index $string, $substring, 0, 1;	# first occurrence
        $first = index $string, $substring, 0, 2;	# second occurrence
        $first = index $string, $substring, 0, 3;	# third occurrence</pre>
<p>If omitted, this fourth parameter would default to 1, thus preversing
the current behaviour.</p>
<p>The <code>rindex</code> function would be unnecessary, being replaced by:</p>
<pre>        $last = index $string, $substring, -1, -1;	# last occurence
        </pre>
<a name='IMPLEMENTATION'></a><h1>IMPLEMENTATION</h1>
<p>Dammit, Jim, I'm a doctor, not an engineer!</p>
</div>
